"""
_*_ : utf-8 _*_ 
@Time: 2023/10/30 21:06
@Author: LWK
@File: 038_字典
@Project: demo01
"""
person = {'name': 'lwk', 'age': 18}

print(person['name'])
print(person['age'])
print(person.get('name'))
print(person.get('sex'))

# 使用[]访问不存在的key，会报错
# print(person['sex'])

# 字典中存在：修改
person['name'] = 'LWK'
print(person)

# 字典中不存在：新增
person['city'] = '河南'
print(person)

del person['city']
print(person)

person.clear()
print(person)

person = {'name': 'lwk', 'age': 18, 'sex': '男'}
age = person.pop('age')
print(age)
print(person)

print(person.keys())
print(person.values())
print(person.items())

for k, v in person.items():
    print(k, v)
